<?php

	header("Content-Type: text/html;charset=utf-8");

	include("function/_nosql.php"); //

	include("function/function.php");
	include("_include.user.judge.php");

	

	$kboy_userid = $_SESSION['kboy_userid'];

	$kboy_user = $_SESSION['kboy_user'];

	

	$action = chkstr(trim($_REQUEST['action']));
	
	$del = chkstr(trim($_REQUEST['del']));

	$caogao = chkstr(trim($_REQUEST['caogao']));
	$active_title = chkstr(trim($_REQUEST['active_title']));

	$active_bigclass = chkstr(trim($_REQUEST['active_bigclass']));
	
	$active_renzheng = chkstr(trim($_REQUEST['renzheng']));

	$active_mingyi = chkstr(trim($_REQUEST['active_mingyi']));

	$active_fanwei = chkstr(trim($_REQUEST['active_fanwei']));

	$active_xianzhi = chkstr(trim($_REQUEST['active_xianzhi']));

	$active_all_money = chkstr(trim($_REQUEST['active_all_money']));

	$active_part_money = chkstr(trim($_REQUEST['active_part_money']));

	$active_end_user = chkstr(trim($_REQUEST['active_end_user']));

	$active_text = chkstr(trim($_REQUEST['active_text']));

	
	if(!empty($_REQUEST['active_pic']))
	{
		foreach ($_REQUEST['active_pic'] as $k => $v) {
			$active_pic[$k] = ltrim($v,'/');
		}
		$active_pic = implode(',', $active_pic);
		
	}
	
	if(!empty($_REQUEST['active_sollimg'])){
		foreach ($_REQUEST['active_sollimg'] as $k => $v) {
			$active_sollimg[$k] = ltrim($v,'/');
		}
		$active_sollimg = implode(',', $active_sollimg);
	}
	
	if(!empty($_REQUEST['active_zhong'])){
		foreach ($_REQUEST['active_zhong'] as $k => $v) {
			$active_zhong[$k] = ltrim($v,'/');
		}
		$active_zhong = implode(',', $active_zhong);
	}
	
	$active_hd_content = chkstr(trim($_REQUEST['active_hd_content']));

	$active_power = chkstr(trim($_REQUEST['active_power']));

	$active_all_line = chkstr(trim($_REQUEST['active_all_line']));

	$active_start_prov = chkstr(trim($_REQUEST['active_start_prov']));

	$active_start_city = chkstr(trim($_REQUEST['active_start_city']));

	$active_end_prov = chkstr(trim($_REQUEST['active_end_prov']));

	$active_end_city = chkstr(trim($_REQUEST['active_end_city']));

	$active_start_time = chkstr(trim($_REQUEST['active_start_time']));

	$active_end_time = chkstr(trim($_REQUEST['active_end_time']));
	
	$active_post_time = chkstr(trim($_REQUEST['active_post_time']));

	$active_center = chkstr(trim($_REQUEST['active_center']));

	$active_center_time = chkstr(trim($_REQUEST['active_center_time']));

	$active_jingdian = chkstr(trim($_REQUEST['active_jingdian']));

	$active_traffic = chkstr(trim($_REQUEST['active_traffic']));

	$active_traffic_info = chkstr(trim($_REQUEST['active_traffic_info']));

	$active_contact = chkstr(trim($_REQUEST['active_contact']));

	$active_contact_people = chkstr(trim($_REQUEST['active_contact_people']));

	$active_contact_phone = chkstr(trim($_REQUEST['active_contact_phone']));

	$active_people = chkstr(trim($_REQUEST['active_people']));

	$active_line = addslashes($_REQUEST['active_line']);

	$active_xingcheng = addslashes($_REQUEST['active_xingcheng']);

	$active_zhuangbei = addslashes($_REQUEST['active_zhuangbei']);

	$active_baoming = addslashes($_REQUEST['active_baoming']);

	if($active_transport){

	$active_transport = implode(',',$_REQUEST['active_transport']);

	}

	$active_charge_details = addslashes($_REQUEST['active_charge_details']);

	$newsid = chkstr(trim($_REQUEST['newsid']));	

	$active_model = intval(trim($_REQUEST['savemodel']));

	$active_ditu = chkstr(trim($_REQUEST['active_ditu']));

	$active_koubei = chkstr(trim($_REQUEST['active_koubei']));

	$active_cva_money = chkstr(trim($_REQUEST['active_cva_money']));
	
	$active_object = chkstr(trim($_REQUEST['active_object']));

	
	

	$active_banner = chkstr(trim($_REQUEST['active_banner']));

	$active_zhubanfang = addslashes($_REQUEST['active_zhubanfang']);

	$active_xiebanfang = addslashes($_REQUEST['active_xiebanfang']);

	$active_hezuopinpai = addslashes($_REQUEST['active_hezuopinpai']);

	$active_hezuomeiti = addslashes($_REQUEST['active_hezuomeiti']);

	

	

	

	$active_favor = 1;





	if(!is_numeric($active_all_money)){

		$active_all_money = 0;

	}

	if(!is_numeric($active_part_money)){

		$active_part_money = 0;

	}

	

	if($action == "add"){
		
		if(empty($caogao)){
			if(strlen($active_title)<1){

			echo erro("游记标题不能为空！");

		}

		if(strlen($active_bigclass)<1){

			echo erro("请选择板块分类！");

		}
		if($active_text == ''){

			echo erro("请填写活动特色！");

		}
		if(!is_numeric($active_bigclass)){

			echo erro("请选择板块分类");

		}
		if(empty($active_pic)){
			echo erro("活动头像图片不能为空");
		}
		if($active_end_time <= $active_start_time){

		    echo erro("活动结束时间必须大于活动开始时间");

		}

		if($active_post_time >= $active_start_time){

		    echo erro("活动开始时间必须大于报名截止的时间");

		}

		$active_state = 2 ;
		//获取活动次数
		$user_activetime = getClassName('kboy_user', 'user_activetime','uid ='.$kboy_userid);
		$user_activetime = $user_activetime + 1;
		$user_km = getClassName('kboy_user', 'user_km','uid ='.$kboy_userid);
		$user_km = $user_km + $active_all_line;
		$user_activetime ="update kboy_user set user_activetime=".$user_activetime.",user_km=".$user_km." where uid=".$kboy_userid;
		mysql_query($user_activetime);
		$tian = strtotime($active_end_time) - strtotime($active_start_time);
		$active_tian = ceil($tian/(60*60*24));	
		// 添加内容

		$mysql = new sqlstr("kboy_forum_active"); 

		$mysql -> set("active_title",$active_title);

		$mysql -> set("active_center_time",$active_center_time);

		$mysql -> set("active_bigclass",$active_bigclass,true);
		
		$mysql -> set("active_renzheng",$active_renzheng);

		$mysql -> set("active_mingyi",$active_mingyi);

		$mysql -> set("active_fanwei",$active_fanwei);

		$mysql -> set("active_xianzhi",$active_xianzhi);

		$mysql -> set("active_all_money",$active_all_money,true);

		$mysql -> set("active_part_money",$active_part_money,true);

		$mysql -> set("active_end_user",$active_end_user);

		$mysql -> set("active_text",$active_text);

		$mysql -> set("active_pic",$active_pic);
		
		$mysql -> set("active_sollimg",$active_sollimg);
		
		$mysql -> set("active_hd_content",$active_hd_content);

		$mysql -> set("active_power",$active_power);

		$mysql -> set("active_all_line",$active_all_line);

		$mysql -> set("active_start_prov",$active_start_prov);

		$mysql -> set("active_start_city",$active_start_city);

		$mysql -> set("active_end_prov",$active_end_prov);
		
		$mysql -> set("active_tian",$active_tian);

		$mysql -> set("active_end_city",$active_end_city);

		$mysql -> set("active_start_time",$active_start_time);

		$mysql -> set("active_end_time",$active_end_time);

		$mysql -> set("active_post_time",$active_post_time);

		$mysql -> set("active_center",$active_center);

		$mysql -> set("active_jingdian",$active_jingdian);

		$mysql -> set("active_traffic",$active_traffic);

		$mysql -> set("active_transport",$active_transport);

		$mysql -> set("active_traffic_info",$active_traffic_info);

		$mysql -> set("active_contact",$active_contact);

		$mysql -> set("active_contact_people",$active_contact_people);

		$mysql -> set("active_contact_phone",$active_contact_phone);

		$mysql -> set("active_people",$active_people);

		$mysql -> set("active_line",$active_line);

		$mysql -> set("active_xingcheng",$active_xingcheng);

		$mysql -> set("active_zhuangbei",$active_zhuangbei);

		$mysql -> set("active_baoming",$active_baoming);

		$mysql -> set("active_charge_details",$active_charge_details);

		$mysql -> set("active_model",$active_model);

		$mysql -> set("active_favor",$active_favor);

		$mysql -> set("active_state",$active_state);

		$mysql -> set("active_ditu",$active_ditu);

		$mysql -> set("active_koubei",$active_koubei);

		$mysql -> set("active_cva_money",$active_cva_money);

		$mysql -> set("active_object",$active_object);

		

		$mysql -> set("active_banner",$active_banner);

		$mysql -> set("active_zhubanfang",$active_zhubanfang);

		$mysql -> set("active_xiebanfang",$active_xiebanfang);

		$mysql -> set("active_hezuopinpai",$active_hezuopinpai);

		$mysql -> set("active_hezuomeiti",$active_hezuomeiti);

		

		

		

		

		

		$mysql -> set("uid",$kboy_userid);

		$news_sql = $mysql -> insertSql();

		$news_res = mysql_query($news_sql);

		if($news_res){

			echo ok("操作成功","forum_activeadd.php?uid=".$kboy_userid);

		}else{

			echo erro("服务器内部错误!");

		}
		}else{
			if(!is_numeric($caogao)){

		  echo erro("参数错误！");

		}

		if(getNewsNums("kboy_forum_active","uid=$kboy_userid and id=$caogao") <1){

		  echo erro("参数错误");

	    }

	    if(strlen($active_title)<1){

			echo erro("游记标题不能为空！");

		}

		if(strlen($active_bigclass)<1){

			echo erro("请选择板块分类！");

		}

		if(!is_numeric($active_bigclass)){

			echo erro("请选择板块分类");

		}

		if($active_end_time <= $active_start_time){

		    echo erro("活动结束时间必须大于活动开始时间");

		}

		if($active_post_time >= $active_start_time){

		    echo erro("活动开始时间必须大于报名截止的时间");

		}
		
		$tian = strtotime($active_end_time) - strtotime($active_start_time);
		$active_tian = ceil($tian/(60*60*24));

		// 修改内容

		$mysql = new sqlstr("kboy_forum_active"); 

		$mysql -> set("active_title",$active_title);

		$mysql -> set("active_center_time",$active_center_time);

		$mysql -> set("active_bigclass",$active_bigclass,true);
		
		$mysql -> set("active_renzheng",$active_renzheng);

		$mysql -> set("active_mingyi",$active_mingyi);

		$mysql -> set("active_fanwei",$active_fanwei);

		$mysql -> set("active_xianzhi",$active_xianzhi);

		$mysql -> set("active_all_money",$active_all_money,true);

		$mysql -> set("active_part_money",$active_part_money,true);

		$mysql -> set("active_end_user",$active_end_user);

		$mysql -> set("active_text",$active_text);

		$mysql -> set("active_pic",$active_pic);
		
		$mysql -> set("active_tian",$active_tian);
		
		$mysql -> set("active_sollimg",$active_sollimg);
		
		$mysql -> set("active_hd_content",$active_hd_content);

		$mysql -> set("active_power",$active_power);

		$mysql -> set("active_all_line",$active_all_line);

		$mysql -> set("active_start_prov",$active_start_prov);

		$mysql -> set("active_start_city",$active_start_city);

		$mysql -> set("active_end_prov",$active_end_prov);

		$mysql -> set("active_end_city",$active_end_city);

		$mysql -> set("active_start_time",$active_start_time);

		$mysql -> set("active_end_time",$active_end_time);

		$mysql -> set("active_post_time",$active_post_time);

		$mysql -> set("active_center",$active_center);

		$mysql -> set("active_jingdian",$active_jingdian);

		$mysql -> set("active_traffic",$active_traffic);

		$mysql -> set("active_transport",$active_transport);

		$mysql -> set("active_traffic_info",$active_traffic_info);

		$mysql -> set("active_contact",$active_contact);

		$mysql -> set("active_contact_people",$active_contact_people);

		$mysql -> set("active_contact_phone",$active_contact_phone);

		$mysql -> set("active_people",$active_people);

		$mysql -> set("active_line",$active_line);

		$mysql -> set("active_xingcheng",$active_xingcheng);

		$mysql -> set("active_zhuangbei",$active_zhuangbei);

		$mysql -> set("active_baoming",$active_baoming);

		$mysql -> set("active_charge_details",$active_charge_details);

		$mysql -> set("active_model",$active_model);

		$mysql -> set("active_ditu",$active_ditu);

		$mysql -> set("active_koubei",$active_koubei);

		$mysql -> set("active_cva_money",$active_cva_money);

		$mysql -> set("active_object",$active_object);

		

		

		$mysql -> set("active_banner",$active_banner);

		$mysql -> set("active_zhubanfang",$active_zhubanfang);

		$mysql -> set("active_xiebanfang",$active_xiebanfang);

		$mysql -> set("active_hezuopinpai",$active_hezuopinpai);

		$mysql -> set("active_hezuomeiti",$active_hezuomeiti);

		

		

		

		

		$news_sql = $mysql -> updateSql("uid=$kboy_userid  and id=$caogao");

		$news_res = mysql_query($news_sql);

		if($news_res){

			echo ok("操作成功","forum_activeadd.php?uid=".$kboy_userid);

		}else{

			echo erro("服务器内部错误!!");

		}
		}
		

	}

	else if($action == "editsave"){

	

	    if(!is_numeric($newsid)){

		  echo erro("参数错误！");

		}

		if(getNewsNums("kboy_forum_active","uid=$kboy_userid and id=$newsid") <1){

		  echo erro("参数错误");

	    }

	    if(strlen($active_title)<1){

			echo erro("游记标题不能为空！");

		}

		if(strlen($active_bigclass)<1){

			echo erro("请选择板块分类！");

		}

		if(!is_numeric($active_bigclass)){

			echo erro("请选择板块分类");

		}

		if($active_end_time <= $active_start_time){

		    echo erro("活动结束时间必须大于活动开始时间");

		}

		if($active_post_time >= $active_start_time){

		    echo erro("活动开始时间必须大于报名截止的时间");

		}
		
		$tian = strtotime($active_end_time) - strtotime($active_start_time);
		$active_tian = ceil($tian/(60*60*24));

		// 修改内容

		$mysql = new sqlstr("kboy_forum_active"); 

		$mysql -> set("active_title",$active_title);

		$mysql -> set("active_center_time",$active_center_time);

		$mysql -> set("active_bigclass",$active_bigclass,true);
		
		$mysql -> set("active_renzheng",$active_renzheng);

		$mysql -> set("active_mingyi",$active_mingyi);

		$mysql -> set("active_fanwei",$active_fanwei);

		$mysql -> set("active_xianzhi",$active_xianzhi);

		$mysql -> set("active_all_money",$active_all_money,true);

		$mysql -> set("active_part_money",$active_part_money,true);

		$mysql -> set("active_end_user",$active_end_user);

		$mysql -> set("active_text",$active_text);

		$mysql -> set("active_pic",$active_pic);
		
		$mysql -> set("active_tian",$active_tian);
		
		$mysql -> set("active_sollimg",$active_sollimg);
		
		$mysql -> set("active_hd_content",$active_hd_content);

		$mysql -> set("active_power",$active_power);

		$mysql -> set("active_all_line",$active_all_line);

		$mysql -> set("active_start_prov",$active_start_prov);

		$mysql -> set("active_start_city",$active_start_city);

		$mysql -> set("active_end_prov",$active_end_prov);

		$mysql -> set("active_end_city",$active_end_city);

		$mysql -> set("active_start_time",$active_start_time);

		$mysql -> set("active_end_time",$active_end_time);

		$mysql -> set("active_post_time",$active_post_time);

		$mysql -> set("active_center",$active_center);

		$mysql -> set("active_jingdian",$active_jingdian);

		$mysql -> set("active_traffic",$active_traffic);

		$mysql -> set("active_transport",$active_transport);

		$mysql -> set("active_traffic_info",$active_traffic_info);

		$mysql -> set("active_contact",$active_contact);

		$mysql -> set("active_contact_people",$active_contact_people);

		$mysql -> set("active_contact_phone",$active_contact_phone);

		$mysql -> set("active_people",$active_people);

		$mysql -> set("active_line",$active_line);

		$mysql -> set("active_xingcheng",$active_xingcheng);

		$mysql -> set("active_zhuangbei",$active_zhuangbei);

		$mysql -> set("active_baoming",$active_baoming);

		$mysql -> set("active_charge_details",$active_charge_details);

		$mysql -> set("active_model",$active_model);

		$mysql -> set("active_ditu",$active_ditu);

		$mysql -> set("active_koubei",$active_koubei);

		$mysql -> set("active_cva_money",$active_cva_money);

		$mysql -> set("active_object",$active_object);

		

		

		$mysql -> set("active_banner",$active_banner);

		$mysql -> set("active_zhubanfang",$active_zhubanfang);

		$mysql -> set("active_xiebanfang",$active_xiebanfang);

		$mysql -> set("active_hezuopinpai",$active_hezuopinpai);

		$mysql -> set("active_hezuomeiti",$active_hezuomeiti);

		

		

		

		

		$news_sql = $mysql -> updateSql("uid=$kboy_userid  and id=$newsid");

		$news_res = mysql_query($news_sql);

		if($news_res){

			echo ok("操作成功","forum_activeedit.php?uid=".$kboy_userid."&newsid=".$newsid);

		}else{

			echo erro("服务器内部错误!!!");

		}

	}

	else if($action == 'delactive' ){//删除草稿箱内的信息

	   if(getNewsNums("kboy_forum_active","uid=$kboy_userid and id=$newsid and active_model=1 ") <1){

		  echo erro("参数错误");

	    }

		$res = mysql_query(" delete from kboy_forum_active where uid=$kboy_userid and id=$newsid and active_model=1 " );

		if($res){

		 $data['result'] = 1;

		}

		else{

		 $data['result'] = 0;

		}

		echo json_encode($data);

		

	}

	else if($action == 'downline'){//活动下线

	    if(!is_numeric($newsid)){

		  echo erro("参数错误！");

		}

		if(getNewsNums("kboy_forum_active","uid=$kboy_userid and id=$newsid") <1){

		  echo erro("参数错误");

	    }

		$active_state = 1;

		//活动次数
		$user_activetime = getClassName('kboy_user', 'user_activetime','uid ='.$kboy_userid);
		$user_activetime = $user_activetime - 1;
		//活动公里
		$user_km = getClassName('kboy_user', 'user_km','uid ='.$kboy_userid);
		//本次活动公里
		$active_all_line = getClassName('kboy_forum_active', 'active_all_line','id ='.$newsid);
		$user_km = $user_km - $active_all_line;
		 
		$user_activetime ="update kboy_user set user_activetime=".$user_activetime.",user_km=".$user_km." where uid=".$kboy_userid;
		mysql_query($user_activetime);
		$mysql = new sqlstr("kboy_forum_active"); 

		$mysql -> set("active_state",$active_state);

		$news_sql = $mysql -> updateSql("uid=$kboy_userid  and id=$newsid");

		$news_res = mysql_query($news_sql);

		if($news_res){

			echo ok("操作成功","user_active.php");

		}else{

			echo erro("服务器内部错误~!");

		}

	}

	else if($action == 'upline'){//活动上线

	    if(!is_numeric($newsid)){

		  echo erro("参数错误！");

		}

		if(getNewsNums("kboy_forum_active","uid=$kboy_userid and id=$newsid") <1){

		  echo erro("参数错误");

	    }

		$active_state = 0;

		$mysql = new sqlstr("kboy_forum_active"); 

		$mysql -> set("active_state",$active_state);

		$news_sql = $mysql -> updateSql("uid=$kboy_userid  and id=$newsid");

		$news_res = mysql_query($news_sql);

		if($news_res){

			echo ok("操作成功","user_active.php");

		}else{

			echo erro("服务器内部错误~~!");

		}

	}

	else if($del == 'image'){
		if(file_exists(ltrim($photo_pic,'/'))){
			
			if(IS_AJAX)
				{
					//异步抓取图片路径
					$path = $_POST['path'];
		//			p($path);
		//			p(1);
					//删除路径
					if(unlink($path)){
						echo 1;
						
					}
					echo 0;
				}
		}
	}else{

		echo erro("参数错误");

	}

?>